package com.sy.server.mapper;

import com.sy.server.dto.CostWithoutDetail;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface CostWithoutDetailMapper {
    @Select({
            "select user_id,day,eat,house,communication,traffic,",
            "daily,education,clothes,snacks,fruits,medical,others,sum",
            "from cost",
            "where user_id = #{userId,jdbcType=INTEGER}",
            "and day between #{beginDate,jdbcType=VARCHAR} and #{endDate,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="user_id", property="userId", jdbcType=JdbcType.INTEGER, id=true),
            @Result(column="day", property="day", jdbcType=JdbcType.VARCHAR, id=true),
            @Result(column="eat", property="eat", jdbcType=JdbcType.DOUBLE),
            @Result(column="house", property="house", jdbcType=JdbcType.DOUBLE),
            @Result(column="communication", property="communication", jdbcType=JdbcType.DOUBLE),
            @Result(column="traffic", property="traffic", jdbcType=JdbcType.DOUBLE),
            @Result(column="daily", property="daily", jdbcType=JdbcType.DOUBLE),
            @Result(column="education", property="education", jdbcType=JdbcType.DOUBLE),
            @Result(column="clothes", property="clothes", jdbcType=JdbcType.DOUBLE),
            @Result(column="snacks", property="snacks", jdbcType=JdbcType.DOUBLE),
            @Result(column="fruits", property="fruits", jdbcType=JdbcType.DOUBLE),
            @Result(column="medical", property="medical", jdbcType=JdbcType.DOUBLE),
            @Result(column="others", property="others", jdbcType=JdbcType.DOUBLE),
            @Result(column="sum", property="sum", jdbcType=JdbcType.DOUBLE),

    })
    List<CostWithoutDetail> selectByBeginEndDay(Integer userId,String beginDate,String endDate);

    @Select({
            "select sum(eat) as eat,sum(house) as house,sum(communication) as communication,sum(traffic) as traffic,",
            "sum(daily) as daily,sum(education) as education,sum(clothes) as clothes,sum(snacks) as snacks,sum(fruits) as fruits,sum(medical) as medical,sum(others) as others",
            "from cost",
            "where user_id = #{userId,jdbcType=INTEGER}",
            "and day between #{beginDate,jdbcType=VARCHAR} and #{endDate,jdbcType=VARCHAR}"
    })
    @Results({
            @Result(column="eat", property="eat", jdbcType=JdbcType.DOUBLE),
            @Result(column="house", property="house", jdbcType=JdbcType.DOUBLE),
            @Result(column="communication", property="communication", jdbcType=JdbcType.DOUBLE),
            @Result(column="traffic", property="traffic", jdbcType=JdbcType.DOUBLE),
            @Result(column="daily", property="daily", jdbcType=JdbcType.DOUBLE),
            @Result(column="education", property="education", jdbcType=JdbcType.DOUBLE),
            @Result(column="clothes", property="clothes", jdbcType=JdbcType.DOUBLE),
            @Result(column="snacks", property="snacks", jdbcType=JdbcType.DOUBLE),
            @Result(column="fruits", property="fruits", jdbcType=JdbcType.DOUBLE),
            @Result(column="medical", property="medical", jdbcType=JdbcType.DOUBLE),
            @Result(column="others", property="others", jdbcType=JdbcType.DOUBLE),
    })
    CostWithoutDetail getSumEachOther(Integer userId, String beginDate, String endDate);
}
